package co.fitstart.mobile.web.controller.profile;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.utils.JsonUtils;
import com.demo2do.core.wechat.web.interceptor.WechatJsConfig;

import co.fitstart.entity.user.User;
import co.fitstart.entity.user.inbody.InbodyRecord;
import co.fitstart.mobile.service.UserService;
import co.fitstart.mobile.web.interceptor.MobileDetect;
import co.fitstart.mobile.web.interceptor.Router;
import co.fitstart.mobile.web.interceptor.WechatAuthority;
import co.fitstart.mobile.web.resolver.Secure;

/**
 * 
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("/profile")
public class ProfileFitController {
    
    @Autowired
    private UserService userService;
    
    
    /**
     * View user inbody index
     * 
     * @param user
     * @return
     */
    @RequestMapping("/inbody")
    @Router
    @WechatAuthority
    @MobileDetect
    @WechatJsConfig
    public ModelAndView index(@Secure User user) {
        
        ModelAndView modelAndView = new ModelAndView("inbody/inbody-index");
        
        InbodyRecord inbodyRecord = userService.getLatestInbodyRecord(user);
        modelAndView.addObject("inbodyRecord", inbodyRecord);
        
        return modelAndView;
    }
    
    /**
     * View user weight chat
     * 
     * @param user
     * @return
     */
    @RequestMapping("/inbody/records")
    @Router
    @WechatAuthority
    @MobileDetect
    @WechatJsConfig
    public ModelAndView inbodyRecord(@Secure User user) {
        
        ModelAndView modelAndView = new ModelAndView("inbody/inbody-record");
        
        List<InbodyRecord> records = userService.listInbodyRecord(user);
        modelAndView.addObject("records", JsonUtils.toJsonString(records));
        
        return modelAndView;
    }
    
    /**
     * View all bwh record here
     * 
     * @param user
     * @return
     */
    @RequestMapping("/bwh/records")
    public ModelAndView bwhRecord(@Secure User user) {
    	
    	ModelAndView modelAndView = new ModelAndView("bwh/bwh-record");
    	
    	return modelAndView;
    }
}
